from apscheduler.schedulers.background import BackgroundScheduler
import pandas as pd

from air_web.data_platform import sql_engine


def proc_finish_time():
    sql = "SELECT * FROM task_log WHERE is_remove=0"
    df = sql_engine.query(sql)
    if (df['task_status'] == 1).all():
        finish_time = df['create_time'].sort_values(ascending=False).tolist()[0]
        df = pd.DataFrame({"module_name": ['dws'], "finish_time": finish_time})
        sql_engine.update_df_by_id(df, "dws_finish_time")
        print("更新后处理时间:", finish_time)


if __name__ == '__main__':
    scheduler = BackgroundScheduler()
    scheduler.add_job(proc_finish_time, 'interval', minutes=1)
    scheduler.start()
